package lt.vin.ht.server.context;

import javax.xml.transform.TransformerFactory;
import javax.xml.validation.SchemaFactory;

import lt.vin.ht.server.GreetingServiceImpl;
import lt.vin.ht.server.dao.SchemaDao;
import lt.vin.ht.server.dao.SrcDao;
import lt.vin.ht.server.dao.impl.SchemaDaoImpl;
import lt.vin.ht.server.dao.impl.SrcDaoImpl;
import lt.vin.ht.server.servlet.HtmlTransformer;
import lt.vin.ht.server.servlet.TransformerServlet;

import org.w3c.tidy.Tidy;

import com.google.inject.servlet.ServletModule;

public class HtServletModule extends ServletModule {
	@Override
	protected void configureServlets() {		
		bind(SchemaDao.class).to(SchemaDaoImpl.class);
		bind(SrcDao.class).to(SrcDaoImpl.class);
		
		bind(Tidy.class).toInstance(getTidy());
		bind(HtmlTransformer.class).toInstance(new HtmlTransformer());
		bind(TransformerFactory.class).toInstance(TransformerFactory.newInstance());
		bind(SchemaFactory.class).toInstance(SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"));
		
		serve("/htmltransformer/greet").with(GreetingServiceImpl.class);
		serve("/transform").with(TransformerServlet.class);
	}
	
	private Tidy getTidy() {
		Tidy result = new Tidy();
		
		result.setXHTML(true);
		
		return result;
	}
}